<template>
  <el-dialog
    :title="title"
    :visible.sync="visible"
    width="65%"
    top="5vh"
    :before-close="handleClose"
  >
    <!-- 员工减少查询模块 -->
    <searchform
     v-if="type == '1'"
      @f_search="f_search"
      tablid="9"
      module="chooseWorker-search-02"
    ></searchform>
    <!-- 列表模块 -->
    <list v-if="type == '1'" ref="tableData" tableid="9" module="personalBasicInformation"></list>

    <!-- 家属减少查询模块 -->
    <searchform
     v-if="type == '2'"
      @f_search="f_search"
      tablid="16"
      module="chooseFamily-search-02"
    ></searchform>
    <!-- 列表模块 -->
    <list v-if="type == '2'" ref="tableData" tableid="16" module="chooseFamily-02"></list>

    <!-- 新增参保员工查询模块 -->
    <searchform
     v-if="type == '3'"
      @f_search="f_search"
      tablid="38"
      module="chooseCompany-search-01"
    ></searchform>
    <!-- 列表模块 -->
    <list v-if="type == '3'" ref="tableData" tableid="38" module="chooseCompany-01"></list>

    <!-- 新增参保家属查询模块 -->
    <searchform
     v-if="type == '4'"
      @f_search="f_search"
      tablid="9"
      module="chooseWorker-search-03"
    ></searchform>
    <!-- 列表模块 -->
    <list v-if="type == '4'" ref="tableData" tableid="9" module="personalBasicInformation"></list>

    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="handleClose">取 消</el-button>
      <el-button size="small" type="primary" @click="chooseSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
module.exports = {
  name: "ChoosePersonCommon",
  components: {
    "list" : httpVueLoader('/admin/html/module/yumenyoutian/system/common/chooseList.vue'),
    "searchform" : httpVueLoader('/admin/html/module/yumenyoutian/system/common/searchForm.vue'),
  },
  props: {
    visible: {
      //控制弹窗，true就弹出
      type: Boolean,
      default: false,
    },
    type:{
      type: String,
      default: '1'
    },
    typeId:{
      type: String,
      default: '1'
    },
    tableid:{
      type: String
    },
    remoteClose: Function, //用于关闭窗口

  },
  data() {
    return {
      chooseRow: {},
      title:"",
    };
  },
  created(){
    if(this.typeId == '1'){
      this.title = '选择员工';
    }else if(this.typeId == '2'){
      this.title = "选择家属";
    }else{
      this.title = "选择单位"
    }
  },
  methods: {
    f_search(dto) {
      this.$refs.tableData.f_search(dto);
    },
    async chooseSubmit() {
        this.chooseRow = this.$refs.tableData.chooseRow;
        console.log(this.chooseRow);
      if (JSON.stringify(this.chooseRow) == "{}") {
        this.$message.error("请先选中一条数据");
        return;
      } else {
        let bhid = '';
        if(this.typeId == '1'){
          bhid = this.chooseRow.aac001;
        }else if(this.typeId == '2'){
          bhid = this.chooseRow.pcc001;
        }else{
          bhid = this.chooseRow.aab001;
        }
        const params = {
          dataid: bhid,
          tableId: this.tableId,
          type: this.typeId
        };
        const res = await api.queryBody(
          "/admin/api/bfmc/BasicInformationModificationController/selectForObject",
          params
        );
        if (res.code == 1) {
          console.log(res);
          this.$parent.loading = true;
          this.$parent.getInputAndList(res.data);
          setTimeout(()=>{
            this.$parent.loading = false;
          },500)
        } else {
          this.$message.error(res.msg);
        }
      }
    },
    // 关闭窗口
    handleClose() {
      this.remoteClose();
    },
  },
};
</script>
